// GLWidget.cpp
//
#include "GLWidget.h"

// ------------------------------------------------------------------------------------------------
GLWidget::GLWidget(QWidget *parent, QGLWidget *share)
    : QGLWidget(QGLFormat(QGL::SampleBuffers), parent, share)
    //, glPainter(this)
    , glThread(this)
{
    setAttribute(Qt::WA_PaintOutsidePaintEvent);
    setAttribute(Qt::WA_DeleteOnClose);
}

// ------------------------------------------------------------------------------------------------
GLWidget::~GLWidget()
{
    stopRendering();
}

// ------------------------------------------------------------------------------------------------
void GLWidget::startRendering()
{
    //glPainter.moveToThread(&glThread);
    //connect(&glThread, SIGNAL(started()), &glPainter, SLOT(start()));
    glThread.start();
}

// ------------------------------------------------------------------------------------------------
void GLWidget::stopRendering()
{
   // glPainter.stop();
    glThread.wait();
}

// ------------------------------------------------------------------------------------------------
void GLWidget::resizeEvent(QResizeEvent *event)
{
    //glPainter.resizeViewport(event->size());
}

// ------------------------------------------------------------------------------------------------
void GLWidget::paintEvent(QPaintEvent *)
{
    // Handled by GLPainter.
}